import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Random;
import java.util.UUID;

public class test {
    public static void main(String[] args) {
            mysql();
//        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
//        System.out.println(uuid.length());
//        int count = new Random().nextInt(uuid.length()-5 > 0 ? uuid.length()-5:uuid.length());
//        System.out.println(count);
//        System.out.println(uuid.substring(count,count+5));
//        String time = "2021-10-03T16:29";
//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        try {
//            System.out.println(format.parse(time.replace("T"," ")+":00"));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
    }
    public static void mysql(){
        String url = "jdbc:mysql://82.156.197.73:3306/test?useUnicode=true&characterEncodeing=UTF-8&useSSL=false&serverTimezone=GMT";
        String user = "root";
        String password = "123456";
        Connection conn=null;
        Statement stat=null;
        ResultSet rs=null;
//        String sql="SELECT * FROM ATM WHERE NAME = '"+name+"' and password = '"+pwd+"'";
        //WHERE NAME = '"+name+"'"
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            //建立连接
            conn= DriverManager.getConnection(url, user, password);
            //创建状态参数
//            stat=conn.createStatement();
//            rs= stat.executeQuery(sql);//select
            while(conn != null) {
                System.out.println("登录成功");
//                System.out.println(rs.getString("name"));
//                System.out.println(rs.getString("password"));
//                System.out.println(rs.getFloat("balance"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            //关闭流
            try {
                if(rs!=null)
                    rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if(stat!=null)
                    stat.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if(conn!=null)
                    conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
